package springtest.nettySocketio.listener;

import org.springframework.stereotype.Service;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.ConnectListener;

/**
 * @author chenzhiqiang
 * @date 2018-07-03 14:52:16
 */

@Service
public class StartListener implements ConnectListener {

    @Override
    public void onConnect(SocketIOClient client) {
        System.out.println("客户端接入" + client.getSessionId().toString());
        System.out.println();
    }

    //
    // public void test() {
    // socketIoServer.addConnectListener(new ConnectListener() {
    //
    // public void onConnect(SocketIOClient client) {
    // System.out.println("客户端接入" + client.getSessionId().toString());
    // System.out.println();
    // // client.sendEvent("hello", "hello");
    // }
    // });
    // socketIoServer.addEventListener("testSocket", User.class, new
    // DataListener<User>() {
    //
    // @Override
    // public void onData(SocketIOClient client, User data, AckRequest
    // ackSender) throws Exception {
    // System.out.println(data);
    // SocketIONamespace namespace = client.getNamespace();
    // Collection<SocketIOClient> allClients = namespace.getAllClients();
    // for (SocketIOClient clients : allClients) {
    // clients.sendEvent("hello", data);
    // }
    // }
    // });
    // }

    // @OnConnect
    // public void onConnect(SocketIOClient client) {
    // System.out.println("客户端已连接" + client.getSessionId().toString());
    // }
    //
    // @OnDisconnect
    // public void onDisconnect(SocketIOClient client) {
    // System.out.println("客户端:" + client.getSessionId() + "断开连接");
    // }
    //
    // @OnEvent(value = "testSocket")
    // public void onEvent(SocketIOClient client, AckRequest request, User data)
    // {
    // System.out.println("发来消息：" + data.getId());
    // socketIoServer.getClient(client.getSessionId()).sendEvent("hello",
    // "backdata");
    // }

}
